﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Componnent.Common;
using WaterRevenueMS.Domain.ViewModels.BasicSet.RelayType;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IRelayTypeService))]
    public class RelayTypeService : CoreServiceBase, IRelayTypeService
    {
        [Import]
        public IRelayTypeRepository RelayTypeRepository { get; set; }

        public IQueryable<RelayType> RelayTypes
        {
            get {return RelayTypeRepository.Entities; }
        }

        public OperationResult Insert(RelayTypeModel model)
        {
            var entity = new RelayType
            {
                Zhong_JLX=model.Zhong_JLX,
                Zhong_JXY=model.Zhong_JXY,
                OrderNo=model.OrderNo,
                CreateDT=DateTime.Now,
                ReviseDT=DateTime.Now
            };
            RelayTypeRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(RelayTypeModel model)
        {
            var entity = RelayTypeRepository.Entities.FirstOrDefault(t => t.Id == model.Id);
            if (entity != null)
            {
                entity.Zhong_JLX = model.Zhong_JLX;
                entity.Zhong_JXY = model.Zhong_JXY;
                entity.OrderNo = model.OrderNo;
                RelayTypeRepository.Update(entity);
            }
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public Componnent.Common.OperationResult Delete(int Id)
        {
            var entity = RelayTypeRepository.Entities.FirstOrDefault(t => t.Id == Id);
            if (entity != null)
            {
                RelayTypeRepository.Delete(entity);
            }
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
